package com.xebest.web.service.impl;

import com.xebest.common.util.XeBaseUtil;
import com.xebest.web.form.XeVenFinSalesBillDetailForm;
import com.xebest.web.mapper.read.XeVenFinSalesBillDetailReadMapper;
import com.xebest.web.mapper.write.XeVenFinSalesBillDetailWriteMapper;
import com.xebest.web.model.XeVenFinSalesBillDetailEntity;
import com.xebest.web.service.XeVenFinSalesBillDetailService;
import com.xebest.web.view.XeVenFinSalesBillDetailView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @desc:收款单商品明细
 * @author: wangyp
 * @createTime: 2017/8/3 14:32
 * @history:
 * @version:v1.0
 */
@Service
public class XeVenFinSalesBillDetailServiceImpl implements XeVenFinSalesBillDetailService {

    @Autowired
    private XeVenFinSalesBillDetailReadMapper xeVenFinSalesBillDetailReadMapper;
    @Autowired
    private XeVenFinSalesBillDetailWriteMapper xeVenFinSalesBillDetailWriteMapper;

     /**
      * 收款单商品明细
      * @author: Wangyp
      * @createTime: 2017/8/3 14:40
      * @param :form
      * @return:
      */
    public List<XeVenFinSalesBillDetailView> queryXeVenFinSalesBillDetailList(XeVenFinSalesBillDetailForm form){
        List<XeVenFinSalesBillDetailView> finSalesBillList = xeVenFinSalesBillDetailReadMapper.queryXeVenFinSalesBillDetailList(form);
        for (XeVenFinSalesBillDetailView view : finSalesBillList) {
            if (view.getCaAreaId()!=null) {
                String area = XeBaseUtil.baseUtil.getOrgAreaName(Integer.parseInt(view.getCaAreaId()));
                view.setCaAreaId(area);
            }
        }
        return finSalesBillList;
    }

    /**
     * 添加收款单商品明细
     * @author: Wangyp
     * @createTime: 2017/8/4 17:52
     * @param : entity
     * @return:
     */
   public int insertSalesBillDetail(XeVenFinSalesBillDetailEntity entity)throws Exception{
        return xeVenFinSalesBillDetailWriteMapper.insertSalesBillDetail(entity);
    }

    /**
     * 批量添加收款单商品明细
     * @param detailList
     * @return
     * @throws Exception
     */
   public int batchInsertSalesBillDetail(List<XeVenFinSalesBillDetailEntity> detailList)throws Exception{
        return xeVenFinSalesBillDetailWriteMapper.batchInsertSalesBillDetail(detailList);
    }


}
